package com.example.com.test;

import android.Manifest;
import android.animation.AnimatorSet;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.com.test.activity.GridViewActivity;
import com.example.com.test.activity.MarqueeTextActivity;
import com.example.com.test.activity.RecyclerViewActivity;
import com.example.com.test.activity.ViewPagerActivity;
import com.example.com.test.adapter.AdapterViewpager;
import com.example.com.test.adapter.MyAdapter;
import com.example.com.test.listener.MyClickListener;
import com.example.com.test.listener.OnDoubleClickListener;
import com.example.com.test.view.Love;
import com.example.com.test.view.LoveLayout;
import com.example.com.test.view.RecordButton;

import java.util.ArrayList;
import java.util.List;

import pub.devrel.easypermissions.EasyPermissions;

public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks,MyClickListener.MyClickCallBack {
    private LoveLayout loveLayout;
    private Love love;
    private ConstraintLayout cl;
    private static final int RC_STORAGE = 1001;
    private RecordButton recordButton;
    private ImageView iv_user;
    private AnimatorSet animatorSet;
    private LinearLayout mLinearLayout;
    private TextView tv_marquee;
    //图片数据
    private String[] image_url = new String[]{
            "http://pic8.nipic.com/20100701/5290458_114840036316_2.jpg",
            "http://img3.3lian.com/2013/s1/20/d/57.jpg",
            "http://pic39.nipic.com/20140226/18071023_164300608000_2.jpg",
            "http://a0.att.hudong.com/15/08/300218769736132194086202411_950.jpg"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        requestPermision();
        initView();
        setListener();


    }

    private void requestPermision() {
        String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA,
                Manifest.permission.RECORD_AUDIO,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE};
        if (EasyPermissions.hasPermissions(this, perms)) {
            // Already have permission, do the thing
            // ...
        } else {
            // Do not have permissions, request them now
            EasyPermissions.requestPermissions(this, "我们的app需要以下权限",
                    RC_STORAGE, perms);
        }
    }

    private void initView() {
        love = findViewById(R.id.love);
        loveLayout = findViewById(R.id.love_Layout);
        cl = findViewById(R.id.cl_user);
        iv_user = findViewById(R.id.iv_user);
        recordButton = findViewById(R.id.record_button);
        tv_marquee = findViewById(R.id.tv_marquee);
    }

    private void setListener() {


        love.setOnTouchListener(new OnDoubleClickListener(new OnDoubleClickListener.DoubleClickCallback() {
            @Override
            public void onDoubleClick() {
                //startActivity(new Intent(MainActivity.this,ViewPagerActivity.class));

                //startActivity(new Intent(MainActivity.this, SeekBarActivity.class));
                startActivity(new Intent(MainActivity.this, MarqueeTextActivity.class));
            }
        }));

        loveLayout.setOnTouchListener(new OnDoubleClickListener(new OnDoubleClickListener.DoubleClickCallback() {
            @Override
            public void onDoubleClick() {
                loveLayout.addLoveView();
            }
        }));

        recordButton.setOnRecordStateChangedListener(new RecordButton.OnRecordStateChangedListener() {
            @Override
            public void onRecordStart() {
                Toast.makeText(MainActivity.this, "开始录制", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onRecordStop() {
                Toast.makeText(MainActivity.this, "结束录制", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onZoom(float percentage) {

            }
        });

        iv_user.setOnTouchListener(new MyClickListener(this));
        tv_marquee.requestFocus();
        tv_marquee.setFocusable(true);

    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {

    }

    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
        finish();
    }

    @Override
    public void oneClick() {
        startActivity(new Intent(MainActivity.this, GridViewActivity.class));

        Toast.makeText(this, "单击", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void doubleClick() {
        Toast.makeText(this, "双击", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void threeClick() {
        Toast.makeText(this, "三击", Toast.LENGTH_SHORT).show();
    }


}
